﻿@model IEnumerable<DynamicMenuDto>

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}

<div class="content-txt">
    <div class="blog-head">
        <h2>Dynamic Menu Management</h2>
    </div>
    <div class="content-info-area">
        <br /><br />
        <div>
            @Html.ActionLink("Add Menu Item", "Create")
        </div>

        <ul>
        @foreach (var item in Model)
        {	
            <li>
                <span>[@item.OrderPosition] @item.Name (@item.Url)</span>
                <span>
                    @Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
                    @if (item.Children.Count == 0) {
                        @Html.ActionLink("Delete", "Delete", new { id = item.Id }) @:|
                    }
                    @Html.ActionLink("Add Menu Item", "Create", new { parentId = item.Id })
                </span>
                @if (item.Children.Count > 0)
                {
                <ul>
                    @foreach (var subitem in item.Children)
                    {
                    <li>
                        <span>[@subitem.OrderPosition] @subitem.Name (@subitem.Url)</span>
                        <span>
                            @Html.ActionLink("Edit", "Edit", new { id = subitem.Id }) |
                            @Html.ActionLink("Delete", "Delete", new { id = subitem.Id }) 
                        </span>
                    </li>
                    }
                </ul>
                }
            </li>
        }
        </ul>
    </div>
</div>
